package com.san.hkhospital.controller;
import com.github.pagehelper.PageInfo;
import com.san.hkhospital.entity.Bed;
import com.san.hkhospital.entity.Room;
import com.san.hkhospital.service.RoomService;
import com.san.hkhospital.service.impl.RoomServiceImpl;
import com.san.hkhospital.vo.ResultVO;
import com.san.hkhospital.vo.RoomTableVo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* (room)表控制层
*
* @author xxxxx
*/
@RestController
@RequestMapping("/room")
public class RoomController {
/**
* 服务对象
*/
@Resource
private RoomServiceImpl roomServiceImpl;
@Resource
private RoomService roomService;
/**
* 通过主键查询单条数据
*
* @param id 主键
* @return 单条数据
*/
@GetMapping("selectOne")
public Room selectOne(Integer id) {
return roomServiceImpl.selectByPrimaryKey(id);
}


@RequestMapping("selectRoom")
public ResultVO selectRoom(@RequestParam Integer sectionId,@RequestParam Integer pageNum ,@RequestParam Integer pageSize){
    PageInfo roomTableVos = roomService.selectAll(sectionId,pageNum,pageSize);
    return ResultVO.success("病房查询成功！",roomTableVos);
}
@PostMapping
    public ResultVO addRoom(@RequestBody Room room){
    boolean flag = roomService.addRoom(room);
    if (flag){
        return ResultVO.success("病房添加成功！");
    }
    return ResultVO.failed("病房添加失败！");
}

@PostMapping("/updateRoomId")
    public ResultVO updateRoomId(@RequestBody Room room){

    int i = roomService.updateRoom(room);
        if (i==0){
            return ResultVO.failed("病房修改失败！");
        }
    return ResultVO.success("病房修改成功！");
}
    @RequestMapping("findOneRoom")
    public ResultVO findOneRoom(@RequestParam Integer roomId){
        Room room = roomService.findOneRoom(roomId);
        return ResultVO.success("查找一个病床成功！",room);
    }
}
